<template>
  <div>
    <el-dialog v-if="dialogVisible"
               :visible.sync="dialogVisible"
               :append-to-body="true" width="80%"
               :close-on-click-modal="false" :before-close="handleClose">
      <div slot="title" style="font-weight: 600;font-size: 15px">
        {{ getTitleDesc(title) }} <span v-if="title === 'edit' || title === 'check'"
                                        style="font-size: 14px;color: #666666">(需求ID: {{dataList.creativeRequest.shortId}} 需求名称: {{
          dataList.creativeRequest.name
        }})</span>
      </div>
      <div class="creative_dialog">
        <request-add :offer-id="offerId" v-if="title === 'add' || title === 'copy'" :close="handleClose"
                     :user-role="userRole" title="add" :subTitle="title" :offerInfo="offerInfo"
                     :dataList="dataList"></request-add>
        <request-edit :offer-id="offerId" v-if="title === 'edit'" :close="handleClose" :user-role="userRole"
                      :title="title" :data-list="dataList" :offerInfo="offerInfo" :detailInfo="detailInfo"
        ></request-edit>
        <request-check :requestid="requestid" :offer-id="offerId" :close="handleClose" :user-role="userRole"
                       :title="title" :data-list="dataList" :offerInfo="offerInfo" :detailInfo="detailInfo"
                       v-if="title === 'check'"></request-check>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import requestAdd from "./creativeRequest-components/request-add";
import requestEdit from "./creativeRequest-components/request-edit";
import requestCheck from "./creativeRequest-components/request-check";

export default {
  name: "request-dialog",
  props: {
    requestid: String,
    dialogVisible: Boolean,
    title: String,
    offerId: String,
    dataList: Object,
    userRole: Object,
    offerInfo: Object,
    detailInfo:Object,
  },
  watch: {
    dialogVisible: {
      deep: true,
      handler(val) {
        if (!val) {
          return;
        }

      }

    }
  },
  components: {
    requestAdd,
    requestEdit,
    requestCheck,
  },
  created() {
  },
  data() {
    return {}
  },
  methods: {
    getTitleDesc(title) {
      if (title == 'add') {
        return '新增需求';
      } else if (title == 'copy') {
        return '复制需求';
      } else if (title == 'check') {
        return '查看需求：';
      } else {
        return '编辑需求：';
      }
    },
    /**
     * 关闭弹窗
     */
    handleClose() {
      this.creativeDetailList = [{}]
      this.$emit('close-dialog')
    }
  }
}
</script>

<style scoped lang="scss">
.creative_dialog {
  background-size: 100% 100%;
}
</style>
